using System;
using System.Collections.Generic;
using System.Timers;
using DC2010.Objects.Base;
using DC2010.Objects.Common;

namespace DC2010.Objects.Data
{
    [Serializable]
    public class DoorInfo : BaseInfo
    {
        public bool IsBreakable { get; set; }     
        public bool IsBroken { get; set; }   
        public bool IsPicklockable { get; set; }
        public bool IsPassable { get; set; }

        public bool CanPassProjectiles { get; set; }

        public int OpenType { get; set; }   
        public int BreakPoints { get; set; }   

        /// <summary>
        /// If door is opened by key. Key will be consumed.
        /// </summary>
        public bool ConsumeKey { get; set; }

        public List<KeyValue> OnOpenEffects { get; set; }
        public List<KeyValue> OnCloseEffects { get; set; }
        
        /// <summary>
        /// IDs of required keys for door open
        /// </summary>		
        public List<string> Keys { get; set; }
		
        /// <summary>
        /// IDs of already consumed keys. Also in data structure.
        /// </summary>				
        public List<string> ConsumedKeys { get; set; }
        
        public int OpenDirection { get; set; }
        public int OpenPosition { get; set; }
        public int OpenThreshold { get; set; }

        private Timer OpenTimer { get; set; }
        
        public DoorInfo()
        {
            Keys = new List<string>();
            OnOpenEffects = new List<KeyValue>();
            OnCloseEffects = new List<KeyValue>();
            OpenTimer = new Timer();

            OpenDirection = 1;  // up
            OpenPosition = 100; // open
            OpenThreshold = 90; // full opened
        }

        public DoorData CreateData()
        {
            DoorData cd = new DoorData();

            cd.InfoId = Id;
            cd.Id = cd.InfoId + "_" + Guid.NewGuid().ToString();

            Root.log.InfoFormat("Core, Created new object with id: {0} based on object {1}", cd.Id, cd.InfoId);

            //TODO: fill with other properties
            Root.I.DoorSystem.AddData(cd);

            return cd;
        }
    }
}
